package com.job.action;

import com.job.model.Resume;
import com.job.model.User;
import com.job.service.UserService;
import org.omg.PortableInterceptor.USER_EXCEPTION;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 用户 相关的动作控制器
 * @author hasee
 */
@Controller
public class UserAction {

    private UserService userService;

    /**
     * 显示用户登录页面
     * @return
     */
    @RequestMapping("/showLogin.do")
    public String showLogin(){
        return "login";
    }

    /**
     * 用户登录
     * @param userName
     * @param pass
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("/userLogin.do")
    public String userLogin(@RequestParam String userName, String pass, Model model, HttpSession session){
      User user= userService.login(userName,pass);
      if (user==null){
          return "login";
      }else {
          session.setAttribute("user",user);
          List<Resume> resumeList=userService.loginGetResume(user.getUserId());
          model.addAttribute("user",user);
          model.addAttribute("resumeList",resumeList);
          return "redirect:resume.do";
      }

    }

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
